<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传统计</title>
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
</head>
<body>

<div id="main" style="width: 1300px;height: 520px;"></div>

<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/echarts.min.js"></script>
<script type="text/javascript">

    $.ajax({
        url:'cloud-record/uploadCount',
        type:'get',
        dataType:'json',
        success:function (result) {
            if (result.code == 200) {
                myChart.setOption({
                    xAxis: {
                        data: result.data.dateList
                    },
                    series: [{
                        name:'上传次数',
                        type: 'bar',
                        data: [{
                            value: result.data.days1,
                            itemStyle: {
                                color: '#FF0000'
                            }
                        }, {
                            value: result.data.days2,
                            itemStyle: {
                                color: '#FF7F00'
                            }
                        }, {
                            value: result.data.days3,
                            itemStyle: {
                                color: '#FFFF00'
                            }
                        }, {
                            value: result.data.days4,
                            itemStyle: {
                                color: '#00FF00'
                            }
                        }, {
                            value: result.data.days5,
                            itemStyle: {
                                color: '#00FFFF'
                            }
                        }, {
                            value: result.data.days6,
                            itemStyle: {
                                color: '#0000FF'
                            }
                        }, {
                            value: result.data.days7,
                            itemStyle: {
                                color: '#8B00FF'
                            }
                        }]
                    }]
                });
            }
        }
    })

    // 基于准备好的dom，初始化echarts实例
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    myChart.resize();
    // 指定图表的配置项和数据
    var option = {
        title: {
            text: '近7日文件上传统计'
        },
        tooltip: {},
        legend: {
            data:['上传次数']
        },
        xAxis: {
            data: []
        },
        yAxis: {},
        series: [{
            name: '上传次数',
            type: 'bar',
            data: []
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

    //3秒钟刷新一次
    setInterval(function () {
        $.ajax({
            url:'cloud-record/uploadCount',
            type:'get',
            dataType:'json',
            success:function (result) {
                if (result.code == 200) {
                    myChart.setOption({
                        xAxis: {
                            data: result.data.dateList
                        },
                        series: [{
                            name:'上传次数',
                            type: 'bar',
                            data: [{
                                value: result.data.days1,
                                itemStyle: {
                                    color: '#FF0000'
                                }
                            }, {
                                value: result.data.days2,
                                itemStyle: {
                                    color: '#FF7F00'
                                }
                            }, {
                                value: result.data.days3,
                                itemStyle: {
                                    color: '#FFFF00'
                                }
                            }, {
                                value: result.data.days4,
                                itemStyle: {
                                    color: '#00FF00'
                                }
                            }, {
                                value: result.data.days5,
                                itemStyle: {
                                    color: '#00FFFF'
                                }
                            }, {
                                value: result.data.days6,
                                itemStyle: {
                                    color: '#0000FF'
                                }
                            }, {
                                value: result.data.days7,
                                itemStyle: {
                                    color: '#8B00FF'
                                }
                            }]
                        }]
                    });
                }
            }
        })
    }, 3000);


</script>
</body>
</html>